import unittest
from time import sleep
import parameterized
from page.l_page_click_select import PageClickSelect
from tools.l_read_data import read_data


def get_data():
    datas = read_data("../data/l_goods_category_select_data.json")
    # 新建空列表
    arrs = []
    for data in datas.values():
        arrs.append((data['all_category'], data['goods_category'], data['expect_search_value']))
    return arrs


class TestClickSelect(unittest.TestCase):
    front = None

    @classmethod
    def setUpClass(cls) -> None:
        cls.front = PageClickSelect()

    @classmethod
    def tearDownClass(cls) -> None:
        sleep(3)
        cls.front.driver.quit()
    # 点击分类商品测试
    @parameterized.parameterized.expand(get_data())
    def test_click_select(self,all_category,goods_category,expect_search_value):
        self.front.page_wait(all_category)
        self.front.page_click_select(goods_category)
        msg = self.front.page_if_exist()
        try:
            self.assertEqual(expect_search_value, msg)
        except AssertionError:
            self.front.get_image('l-c1-')
            raise
        finally:
            self.front.page_back_home()
